package com.swgk.core.util;

import android.content.Context;

import androidx.core.content.ContextCompat;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.swgk.core.R;


import java.util.List;

/**
 * @author: 杨畔
 * @date: 2020/12/28 10:06
 * @Description: 选择器帮助类
 */
public class PickerHelper {
    private Context context;

    private PickerHelper(Context context) {
        this.context = context;
    }

    public static PickerHelper with(Context context) {
        return new PickerHelper(context);
    }

    /**
     * 获取通用类型单选器
     */
    public <T> OptionsPickerView<T> getCommonPicker(List<T> options1Items,
                                                    OnOptionsSelectListener listener) {
        return getCommonPicker("", options1Items, listener);
    }

    public <T> OptionsPickerView<T> getCommonPicker(String title,
                                                    List<T> options1Items,
                                                    OnOptionsSelectListener listener) {
        OptionsPickerView<T> pickerView = getCommonBuild(title, listener).build();
        pickerView.setPicker(options1Items);
        return pickerView;
    }

    public <T> OptionsPickerView<T> getCommonPicker(String title,
                                                    List<T> options1Items, int position,
                                                    OnOptionsSelectListener listener) {
        OptionsPickerView<T> pickerView = getCommonBuild(title, listener).build();
        pickerView.setPicker(options1Items);
        pickerView.setSelectOptions(position);
        return pickerView;
    }

    /**
     * 获取通用类型双选器
     */
    public <T> OptionsPickerView<T> getCommonPicker(List<T> options1Items,
                                                    List<List<T>> options2Items,
                                                    OnOptionsSelectListener listener) {
        return getCommonPicker("", options1Items, options2Items, listener);
    }

    public <T> OptionsPickerView<T> getCommonPicker(String title,
                                                    List<T> options1Items,
                                                    List<List<T>> options2Items,
                                                    OnOptionsSelectListener listener) {
        OptionsPickerView<T> pickerView = getCommonBuild(title, listener).build();
        pickerView.setPicker(options1Items, options2Items);
        return pickerView;
    }

    /**
     * 获取通用类型三选器
     */
    public <T> OptionsPickerView<T> getCommonPicker(List<T> options1Items,
                                                    List<List<T>> options2Items,
                                                    List<List<List<T>>> options3Items,
                                                    OnOptionsSelectListener listener) {
        return getCommonPicker("", options1Items, options2Items, options3Items, listener);
    }

    public <T> OptionsPickerView<T> getCommonPicker(String title,
                                                    List<T> options1Items,
                                                    List<List<T>> options2Items,
                                                    List<List<List<T>>> options3Items,
                                                    OnOptionsSelectListener listener) {
        OptionsPickerView<T> pickerView = getCommonBuild(title, listener).build();
        pickerView.setPicker(options1Items, options2Items, options3Items);
        return pickerView;
    }

    /**
     * 获取通用样式选择器（不带数据）
     */

    public <T> OptionsPickerView<T> getCommonPicker(OnOptionsSelectListener listener) {
        return getCommonPicker("", listener);
    }

    public <T> OptionsPickerView<T> getCommonPicker(String title, OnOptionsSelectListener listener) {
        return getCommonBuild(title, listener).build();
    }

    /**
     * 获取自定义builder选择器
     */
    public OptionsPickerBuilder getCustomPicker(OnOptionsSelectListener listener) {
        return getCommonBuild(listener);
    }

    /**
     * 获取统一选择样式
     */
    public OptionsPickerBuilder getCommonBuild(OnOptionsSelectListener listener) {
        return getCommonBuild("", listener);
    }

    public OptionsPickerBuilder getCommonBuild(String title, OnOptionsSelectListener listener) {
        return new OptionsPickerBuilder(context, listener)
                .setSubmitColor(ContextCompat.getColor(context, R.color.color_5792FD))
                .setCancelColor(ContextCompat.getColor(context, R.color.f666666))
                .setTitleColor(ContextCompat.getColor(context, R.color.color_969696))
                .setTitleSize(15)
                .setSubCalSize(15)
                .setTitleText(title);
    }

    public OptionsPickerBuilder getCommonSpacingBuild(String title, OnOptionsSelectListener listener) {
        return new OptionsPickerBuilder(context, listener)
                .setSubmitColor(ContextCompat.getColor(context, R.color.color_5792FD))
                .setCancelColor(ContextCompat.getColor(context, R.color.f666666))
                .setTitleColor(ContextCompat.getColor(context, R.color.color_969696))
                .setTitleSize(15)
                .setSubCalSize(15)
                .setLineSpacingMultiplier(2)
                .setTitleText(title);
    }

    /**
     * 获取统一选择样式(时间)
     */
    public TimePickerBuilder getCommonTimeBuild(OnTimeSelectListener listener) {
        return getCommonTimeBuild("", listener);
    }

    public TimePickerBuilder getCommonTimeBuild(String title, OnTimeSelectListener listener) {
        return new TimePickerBuilder(context, listener)
                .setSubmitColor(ContextCompat.getColor(context, R.color.color_5792FD))
                .setCancelColor(ContextCompat.getColor(context, R.color.f666666))
                .setTitleColor(ContextCompat.getColor(context, R.color.color_969696))
                .setTitleSize(15)
                .setSubCalSize(15)
                .setTitleText(title);
    }

}
